package com.atguigu.daijia.customer.controller;

import com.atguigu.daijia.common.login.Login;
import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.common.util.AuthContextHolder;
import com.atguigu.daijia.customer.service.CustomerService;
import com.atguigu.daijia.model.form.customer.UpdateWxPhoneForm;
import com.atguigu.daijia.model.vo.customer.CustomerLoginVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Tag(name = "客户API接口管理")
@RestController
@RequestMapping("/customer")
@SuppressWarnings({"unchecked", "rawtypes"})
public class CustomerController {

    public static void main(String[] args) {
        String str = "a";
        String encode = Base64.encodeBase64String(str.getBytes());
        System.out.println(encode);
    }

    @Autowired
    private CustomerService customerService;


    @GetMapping("/login/{code}")
    public Result<String> login(@PathVariable String code){
        return Result.ok(customerService.login(code));
    }

//    @Operation(summary = "获取客户登录信息")
//    @GetMapping("/getCustomerLoginInfo")
//    public Result<CustomerInfo> getCustomerLoginInfo(@RequestHeader(value = "token") String token){
//        return Result.ok(customerService.getCustomerLoginInfo(token));
//    }
    @Operation(summary = "获取客户登录信息")
    @Login
    @GetMapping("/getCustomerLoginInfo")
    public Result<CustomerLoginVo> getCustomerLoginInfo() {
        Long customerId = AuthContextHolder.getUserId();
        System.out.println("customerId:" + customerId);
        return Result.ok(customerService.getCustomerLoginInfo(customerId));
    }

    @PostMapping("updateWxPhone")
    public Result updateWxPhone(@RequestBody UpdateWxPhoneForm updateWxPhoneForm){
        log.info("updateWxPhone中前端传入的customId:【{}】", updateWxPhoneForm.getCustomerId());
        log.info("updateWxPhone中前端传入的code:【{}】", updateWxPhoneForm.getCode());
        return Result.ok(true);
    }
}

